package cn.ronghuanet;

import cn.ronghuanet.interceptor.LoginInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@SpringBootApplication
@MapperScan("cn.ronghuanet.*.mapper") // 扫描mapper的接口
@ServletComponentScan("cn.ronghuanet.listener")   // 扫描Servlet组件
public class CrmAppStart implements WebMvcConfigurer {

    public static void main(String[] args) {
        SpringApplication.run(CrmAppStart.class, args);
    }


    @Autowired
    private LoginInterceptor loginInterceptor;

    /**
     * 添加拦截器
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/**")     // 要拦截的path
                .excludePathPatterns("/login","/logout");   // 放行的path
    }
}
